package com.wjc.struts.action.user;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.wjc.hibernate.bean.User;
import com.wjc.service.user.UserService;

public class RegistryAction extends ActionSupport implements ModelDriven<User>, ServletRequestAware {

	private static final long serialVersionUID = -1L;

	private User user = new User();

	private HttpServletRequest request;

	@Autowired
	private UserService userService;

	public String login() throws Exception {

		String result = userService.loginUser(user);

		return result;
	}

	public String registry() {
		userService.registryUser(user);
		return "success";
	}

	public String activate() {
		userService.activate(user, request.getParameter("validateCode"));
		return "success";
	}

	public String json() {
		user.setEmail("jwang");

		return "success";
	}

	@Override
	public User getModel() {
		// TODO Auto-generated method stub
		return user;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

}
